/*    */ package com.zimbra.cs.dav.service.method;
/*    */ 
/*    */ import com.zimbra.cs.dav.DavContext;
/*    */ import com.zimbra.cs.dav.DavException;
/*    */ import com.zimbra.cs.dav.resource.Collection;
/*    */ import com.zimbra.cs.dav.resource.UrlNamespace;
/*    */ import com.zimbra.cs.dav.service.DavMethod;
/*    */ import com.zimbra.cs.mailbox.MailItem.Type;
/*    */ import java.io.IOException;
/*    */ import javax.servlet.http.HttpServletResponse;
/*    */ import org.dom4j.Document;
/*    */ import org.dom4j.Element;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class MkAddressbook
/*    */   extends DavMethod
/*    */ {
/*    */   public static final String MKADDRESSBOOK = "MKADDRESSBOOK";
/*    */   
/*    */   public String getName()
/*    */   {
/* 40 */     return "MKADDRESSBOOK";
/*    */   }
/*    */   
/*    */   public void handle(DavContext ctxt) throws DavException, IOException
/*    */   {
/* 45 */     String user = ctxt.getUser();
/* 46 */     String name = ctxt.getItem();
/*    */     
/* 48 */     if ((user == null) || (name == null))
/* 49 */       throw new DavException("invalid uri", 403, null);
/* 50 */     Element top = null;
/* 51 */     if (ctxt.hasRequestMessage()) {
/* 52 */       Document doc = ctxt.getRequestMessage();
/* 53 */       top = doc.getRootElement();
/* 54 */       if (!top.getName().equals("mkaddressbook")) {
/* 55 */         throw new DavException("msg " + top.getName() + " not allowed in MKADDRESSBOOK", 400, null);
/*    */       }
/*    */     }
/* 58 */     Collection col = UrlNamespace.getCollectionAtUrl(ctxt, ctxt.getPath());
/* 59 */     Collection newone = col.mkCol(ctxt, name, MailItem.Type.CONTACT);
/* 60 */     boolean success = false;
/*    */     try {
/* 62 */       PropPatch.handlePropertyUpdate(ctxt, top, newone, true, "MKADDRESSBOOK");
/* 63 */       success = true;
/*    */     } finally {
/* 65 */       if (!success)
/* 66 */         newone.delete(ctxt);
/*    */     }
/* 68 */     ctxt.setStatus(201);
/* 69 */     ctxt.getResponse().addHeader("Cache-Control", "no-cache");
/*    */   }
/*    */   
/*    */   public void checkPrecondition(DavContext ctxt)
/*    */     throws DavException
/*    */   {}
/*    */   
/*    */   public void checkPostcondition(DavContext ctxt)
/*    */     throws DavException
/*    */   {}
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/dav/service/method/MkAddressbook.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */